package com.higgins.client.agentapp.controller;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.higgins.client.agentapp.components.AdvertisedJobListBox;
import com.higgins.client.agentapp.components.AgencyListBox;
import com.higgins.client.agentapp.components.AgentListBox;
import com.higgins.client.agentapp.components.CorrespondenceTable;
import com.higgins.client.agentapp.datamodel.AdvertisedJobDTO;
import com.higgins.client.agentapp.interfaces.AdvertisedJobListChangeHandler;
import com.higgins.client.agentapp.interfaces.AgencyListChangeHandler;
import com.higgins.client.agentapp.interfaces.AgencyListListener;
import com.higgins.client.agentapp.interfaces.AgentListChangeHandler;
import com.higgins.client.agentapp.interfaces.AgentListListener;
import com.higgins.client.agentapp.interfaces.JobListListener;

public class CorrespondencePanelController	implements AdvertisedJobListChangeHandler, AgencyListChangeHandler, AgentListChangeHandler	{
	private AgencyListBox agencyListBox;
	private AgentListBox agentListBox;
	private AdvertisedJobListBox advertisedJobListBox;
	private CorrespondenceTable correspondenceTable;
	
	public void setAgencyListBox(AgencyListBox agencyListBox)	{
		this.agencyListBox = agencyListBox;
		agencyListBox.addAgencyListChangeHandler(this);
	}
	public void setAgentListBox(AgentListBox agentListBox)	{
		this.agentListBox = agentListBox;
		agentListBox.addAgentListChangeHandler(this);
	}
	public void setAdvertisedJobListBox(AdvertisedJobListBox advertisedJobListBox)	{
		this.advertisedJobListBox = advertisedJobListBox;
		advertisedJobListBox.addAgentListChangeHandler(this);
	}
	public void setCorrespondenceTable(CorrespondenceTable correspondenceTable)	{
		this.correspondenceTable = correspondenceTable;
	}
	@Override
	public void onAgencyListChange(ChangeEvent event) {
		correspondenceTable.setAgencyId(agencyListBox.getAgencyId());
		agentListBox.setAgencyId(agencyListBox.getAgencyId());
		advertisedJobListBox.setAgencyId(agencyListBox.getAgencyId());
	}
	@Override
	public void onAgentListChange(ChangeEvent event) {
		advertisedJobListBox.setAgentId(agentListBox.getAgentId());
	}
	@Override
	public void onAdvertisedJobListChange(ChangeEvent event) {
		AdvertisedJobDTO advertisedJobDTO = advertisedJobListBox.getAdvertisedJobDTO();
		correspondenceTable.setAdvertisedJobDTO(advertisedJobDTO);
	}

}
